package com.simple.entity;

import lombok.Getter;
import lombok.Setter;

/**
 * 返回状态封装
 */
@Getter
@Setter
public class CodeResult {
    private String code;//状态码
    private String message;//提示信息
    private String icon;//提示信息图标

    public CodeResult(){};
    public CodeResult(String code, String message, String icon) {
        this.code = code;
        this.message = message;
        this.icon = icon;
    }
    public static CodeResult customResult(Object object) {
        return (object==null)?success(StatusCode.SUCCESS):fail(StatusCode.FAIL);
    }
//    //自定义参数方法
//    public static CodeResult customResult(String code, String message, String icon) {
//        return new CodeResult(code,message,icon);
//    }
//    public static CodeResult customResult(String message) {
//        return new CodeResult(null,message,null);
//    }
    //返回成功
    public static CodeResult success(StatusCode code) {
        return new CodeResult(code.getCode(),code.getMessage(),code.getIcon());
    }
    public static CodeResult success() {
        return new CodeResult(StatusCode.SUCCESS.getCode(),StatusCode.SUCCESS.getMessage(),StatusCode.SUCCESS.getIcon());
    }
    public static CodeResult success(String message) {
        return new CodeResult(StatusCode.SUCCESS.getCode(),message,StatusCode.SUCCESS.getIcon());
    }
    //返回失败
    public static CodeResult fail(StatusCode code) {
        return new CodeResult(code.getCode(),code.getMessage(),code.getIcon());
    }
    public static CodeResult fail(String message) {
        return new CodeResult(StatusCode.FAIL.getCode(),message,StatusCode.FAIL.getIcon());
    }

}
